
//
//  MXHomeShowPhotoTableViewCell.m
//  MXの衣柜
//
//  Created by 马霄 on 15/8/12.
//  Copyright (c) 2015年 霄 马. All rights reserved.
//
#define WIDTH ([UIScreen mainScreen].bounds.size.width)
#define HEIGHT ([UIScreen mainScreen].bounds.size.height)
#import "MXHomeShowPhotoVC.h"
#import "MXHomeShowPhotoTableViewCell.h"
#import "UIImageView+WebCache.h"

@interface MXHomeShowPhotoTableViewCell ()
@property (nonatomic, retain) UIImageView *iconImageView;

@property (nonatomic, retain) UILabel *nameLabel;

@property (nonatomic, retain) UILabel *timeLabel;

@property (nonatomic, retain) UILabel *desLabel;

@property (nonatomic, retain) UIImageView *mainImageView;

@end
@implementation MXHomeShowPhotoTableViewCell
- (void)dealloc
{
    [_showPhotoModelS release];
    [_iconImageView release];
    [_nameLabel release];
    [_timeLabel release];
    [_desLabel release];
    [_mainImageView release];
    [super dealloc];
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.iconImageView = [[[UIImageView alloc] init] autorelease];
        [self.contentView addSubview:self.iconImageView];
        
        self.nameLabel = [[[UILabel alloc] init] autorelease];
        [self.contentView addSubview:self.nameLabel];
        
        self.timeLabel = [[[UILabel alloc] init] autorelease];
        self.timeLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:self.timeLabel];
        
        self.desLabel = [[[UILabel alloc] init] autorelease];
        self.desLabel.numberOfLines = 2;
        self.desLabel.font = [UIFont systemFontOfSize:14];
        if (self.desLabel) {
            [self.contentView addSubview:self.desLabel];
        } else {
            self.desLabel.hidden = YES;
        }
        
        self.mainImageView = [[[UIImageView alloc] init] autorelease];
        [self.contentView addSubview:self.mainImageView];
    }
    return self;
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    
//    CGFloat margin = 10;
    
    CGFloat iconImageViewX = WIDTH / 375 * 10;
    CGFloat iconImageViewY = HEIGHT / 667 * 10;
    CGFloat iconImageViewW = WIDTH / 375 * 40;
    CGFloat iconImageViewH = iconImageViewW;
    self.iconImageView.frame = CGRectMake(iconImageViewX, iconImageViewY, iconImageViewW, iconImageViewH);
    
    CGFloat nameLabelX = WIDTH / 375 * 10 + iconImageViewW + iconImageViewX;
    CGFloat nameLabelY = iconImageViewY;
    CGFloat nameLabelW = WIDTH / 375 * 200;
    CGFloat nameLabelH = iconImageViewH / 2;
    self.nameLabel.frame = CGRectMake(nameLabelX, nameLabelY, nameLabelW, nameLabelH);
    
    CGFloat timeLabelX = nameLabelX;
    CGFloat timeLabelY = nameLabelY + nameLabelH;
    CGFloat timeLabelW = WIDTH / 375 * 150;
    CGFloat timeLabelH = iconImageViewH / 2;
    self.timeLabel.frame = CGRectMake(timeLabelX, timeLabelY, timeLabelW, timeLabelH);
    
    
    
    if (self.desLabel.text.length > 0) {
        
        CGFloat desLabelX = WIDTH / 375 * 10;
        CGFloat desLabelY = iconImageViewH + iconImageViewY + HEIGHT / 667 * 10;
        CGFloat desLabelW = WIDTH - 2 * desLabelX;
        CGFloat desLabelH = HEIGHT / 667 * 40;
        self.desLabel.frame = CGRectMake(desLabelX, desLabelY, desLabelW, desLabelH);
        
        CGFloat mainImageViewX = WIDTH / 375 * 10;
        CGFloat mainImageViewY = desLabelH + desLabelY + HEIGHT / 667 * 10;
        CGFloat mainImageViewW = desLabelW;
        CGFloat mainImageViewH = mainImageViewW;
        self.mainImageView.frame = CGRectMake(mainImageViewX, mainImageViewY, mainImageViewW, mainImageViewH);
    } else  {
        
        self.desLabel.hidden = YES;
        
        CGFloat mainImageViewX = WIDTH / 375 * 10;
        CGFloat mainImageViewY = iconImageViewY + iconImageViewH + HEIGHT / 667 * (2 * 10);
        CGFloat mainImageViewW = WIDTH - WIDTH / 375 * (2 * 10);
        CGFloat mainImageViewH = mainImageViewW;
        self.mainImageView.frame = CGRectMake(mainImageViewX, mainImageViewY, mainImageViewW, mainImageViewH);
    }
    
}
-(void)GetShowPhotoInfo:(MXHomeShowPhotoModel *)model
{
    if (_showPhotoModelS != model) {
        [_showPhotoModelS release];
        _showPhotoModelS = [model retain];
    }
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.head_pic] placeholderImage:[UIImage imageNamed:@"plaseholder"]];
    
    self.nameLabel.text = model.nick_name;
    
    self.timeLabel.text = model.create_time;
    
    if (self.desLabel.text == nil) {
        self.desLabel.text = model.comment;
    }
    [self.mainImageView sd_setImageWithURL:[NSURL URLWithString:model.image]placeholderImage:[UIImage imageNamed:@"plaseholder"]];
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
